import unittest

import requests

class TestIhrmLogin(unittest.TestCase):
#登入成功
    def test01_login_success(self):

        url=" http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":"13800000002","password":"123456"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登入成功",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json()["success"])
        self.assertEqual(10000, resp.json()["code"])
        self.assertEqual("操作成功", resp.json()["msg"])


#密码错误
    def test02_login_fail(self):

        url="http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":"13800000002","password":"123456789"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("密码错误",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json()["success"])
        self.assertEqual(20001, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])
#手机号为空
    def test02_login_fail(self):

        url="http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":None,"password":"123456789"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("密码错误",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json()["success"])
        self.assertEqual(20001, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])

#用户名错误
    def test02_login_fail(self):

        url="http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":13800000005,"password":"123456789"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("密码错误",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json()["success"])
        self.assertEqual(20001, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])
#密码为空
    def test02_login_fail(self):

        url="http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":13800000002,"password":None}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("密码错误",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json()["success"])
        self.assertEqual(20001, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])
#多参
    def test01_login_success(self):

        url=" http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":"13800000002","password":"123456","adc":"1111"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登入成功",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json()["success"])
        self.assertEqual(10000, resp.json()["code"])
        self.assertEqual("操作成功", resp.json()["msg"])

#少参
    def test01_login_success(self):

        url=" http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"mobile":"13800000002"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登入成功",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json()["success"])
        self.assertEqual(10000, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])

#错误参数
    def test01_login_success(self):

        url=" http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type:application/json"}
        json_data = {"ddd":"13800000002","password":"123456"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登入成功",resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json()["success"])
        self.assertEqual(10000, resp.json()["code"])
        self.assertEqual("用户名或者密码错误", resp.json()["msg"])
